package com.rongchuan.wt.controller;


import com.rongchuan.wt.annotation.OperationLog;
import com.rongchuan.wt.entity.Department;
import com.rongchuan.wt.result.Result;
import com.rongchuan.wt.service.IDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/department")
@Api(tags ="部门管理模块接口")
@Slf4j

public class DepartmentController {

    @Autowired
    private IDepartmentService departmentService;

    /**
     * 添加部门信息
     * @param department
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加部门信息")
    @OperationLog("添加员工")
    public Result<String> add(@RequestBody Department department){
        log.info("部门信息:{}",department);
        departmentService.addDepartment(department);
        return Result.success();
    }
    /**
     * 查询部门信息(支持部门名称模糊查询)
     */
    @GetMapping("/query")
    @ApiOperation("查询部门信息(可按部门名称模糊查)")
    public Result<List<Department>> query( Department department){
        List<Department> dep_List = departmentService.queryDepartment(department);
        return Result.success(dep_List);
    }

    /**
     * 更新部门信息
     */
    @PostMapping("/update")
    @ApiOperation("更新部门信息")
    public Result<String> update(@RequestBody Department department){
        departmentService.updateDepartment(department);
        return Result.success();
    }

    /**
     * 删除部门信息
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除部门信息")
    public Result<String> deleteById(@RequestBody Long id){
        departmentService.deleteDepartment(id);
        return Result.success();
    }
}
